const db = wx.cloud.database({
  env: "treeworld-2g5yvz9s899bf4a6"
})
var util = require('../../utils/time.js');
const app = getApp()

Component({
  pageLifetimes: {
    show() {
      if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 1
        })
      }
    }
  },
  properties: {
    popr: {
      type: Number,
      default: 0
    }, 
  },

  data: {
    tz_list: [],
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,

  },
  created() {
    this.list()


  },
  methods: {
    list() {
      const a = db.command
      db.collection('press').limit(20).orderBy('browse', 'desc').orderBy('_createTime','asc').where({
        // and 方法用于指定一个 "与" 条件，此处表示需同时满足 _.gt(30) 和 _.lt(70) 两个条件
        browse: a.gt(10)
      }).get().then(res => {
        this.setData({
          xw_list: res.data
        })
      })
   
        wx.cloud.callFunction({
          name: 'userlist',
        }).then(res => {
          this.setData({
            userlist: res.result.data
          })
   
        })
      db.collection('press').where({
        Top:true
      }).get().then(res => {

        this.setData({
          tz_list: res.data
        })
      })

      wx.cloud.callFunction({
        name: 'user_browse',
      }).then(res => {
       this.setData({
          t_data_rs:res.result.total+23
        })
 
      })
      // const _ = db.command
      // var today =  util.getCurrentTime2()

      // db.collection('user').where({
      //   endtime:_.and(_.gte(today+" 00:00:00"),_.lte(today+" 23:59:59"))
      // }).get().then(res => {

      //   this.setData({
      //     t_data_rs:res.data.length+23
      //   })

    
      // })

    },

    tz(e) {

      wx.navigateTo({
        url: "../../pages/" + e.currentTarget.dataset.a + "?id=" + e.currentTarget.dataset.id
      })
    },
  }
})